﻿Imports System
Imports System.Globalization

Namespace System.Workflow.ComponentModel
    <Serializable> _
    Public NotInheritable Class ActivityExecutionStatusChangedEventArgs
        Inherits EventArgs
        ' Methods
        Friend Sub New(ByVal executionStatus As ActivityExecutionStatus, ByVal executionResult As ActivityExecutionResult, ByVal activity As Activity)
            Me.status = executionStatus
            Me.activityExecutionResult = executionResult
            Me.activityQualifiedName = activity.QualifiedName
            Me.stateId = activity.ContextActivity.ContextId
        End Sub

        Public Overrides Function ToString() As String
            Return String.Concat(New String() { "ActivityStatusChange('(", Me.stateId.ToString(CultureInfo.CurrentCulture), ")", Me.activityQualifiedName, "', ", Activity.ActivityExecutionStatusEnumToString(Me.ExecutionStatus), ", ", Activity.ActivityExecutionResultEnumToString(Me.ExecutionResult), ")" })
        End Function


        ' Properties
        Public ReadOnly Property Activity As Activity
            Get
                Dim activityByName As Activity = Nothing
                If (Not Me.workflowCoreRuntime Is Nothing) Then
                    Dim contextActivityForId As Activity = Me.workflowCoreRuntime.GetContextActivityForId(Me.stateId)
                    If (Not contextActivityForId Is Nothing) Then
                        activityByName = contextActivityForId.GetActivityByName(Me.activityQualifiedName)
                    End If
                End If
                Return activityByName
            End Get
        End Property

        Friend WriteOnly Property BaseExecutor As IWorkflowCoreRuntime
            Set(ByVal value As IWorkflowCoreRuntime)
                Me.workflowCoreRuntime = value
            End Set
        End Property

        Public ReadOnly Property ExecutionResult As ActivityExecutionResult
            Get
                Return Me.activityExecutionResult
            End Get
        End Property

        Public ReadOnly Property ExecutionStatus As ActivityExecutionStatus
            Get
                Return Me.status
            End Get
        End Property


        ' Fields
        Private activityExecutionResult As ActivityExecutionResult
        Private activityQualifiedName As String
        Private stateId As Integer = -1
        Private status As ActivityExecutionStatus
        <NonSerialized> _
        Private workflowCoreRuntime As IWorkflowCoreRuntime
    End Class
End Namespace

